﻿using PcapDotNet.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pcap.NetSample
{
    class 打印网卡设备详细信息
    {
        #region 打印网卡设备详细信息
        /// <summary>
        /// https://github.com/PcapDotNet/Pcap.Net/wiki/Pcap.Net-Tutorial-Obtaining-advanced-information-about-installed-devices
        /// 获取设备详细信息
        /// </summary>
        internal static void ObtainingAdvancedInformationAboutInstalledDevices()
        {
            // Retrieve the interfaces list
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            // Scan the list printing every entry
            for (int i = 0; i != allDevices.Count(); ++i)
                DevicePrint(allDevices[i]);
        }

        // Print all the available information on the given interface
        private static void DevicePrint(LivePacketDevice device)
        {
            // Name
            Console.WriteLine(device.Name);

            // Description
            if (device.Description != null)
                Console.WriteLine("\tDescription: " + device.Description);

            // Loopback Address
            Console.WriteLine("\tLoopback: " +
                              (((device.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback)
                                   ? "yes"
                                   : "no"));

            // IP addresses
            foreach (DeviceAddress address in device.Addresses)
            {
                Console.WriteLine("\tAddress Family: " + address.Address.Family);

                if (address.Address != null)
                    Console.WriteLine(("\tAddress: " + address.Address));

                switch (address.Address.Family)
                {
                    case SocketAddressFamily.Bluetooth:
                        break;
                    case SocketAddressFamily.Iclfxbm:
                        break;
                    case SocketAddressFamily.TcnMessage:
                        break;
                    case SocketAddressFamily.TcnProcess:
                        break;
                    case SocketAddressFamily.NetworkDesigners:
                        break;
                    case SocketAddressFamily.Irda:
                        break;
                    case SocketAddressFamily.Ieee12844:
                        break;
                    case SocketAddressFamily.Cluster:
                        break;
                    case SocketAddressFamily.Internet6:
                        Console.WriteLine($"IPV6 Address: {((IpV6SocketAddress)address.Address).Address}");
                        break;
                    case SocketAddressFamily.Atm:
                        break;
                    case SocketAddressFamily.Ban:
                        break;
                    case SocketAddressFamily.Unknown1:
                        break;
                    case SocketAddressFamily.Firefox:
                        break;
                    case SocketAddressFamily.VoiceView:
                        break;
                    case SocketAddressFamily.NetBios:
                        break;
                    case SocketAddressFamily.AppleTalk:
                        break;
                    case SocketAddressFamily.HyperChannel:
                        break;
                    case SocketAddressFamily.Lat:
                        break;
                    case SocketAddressFamily.DirectDataLinkInterface:
                        break;
                    case SocketAddressFamily.DECnet:
                        break;
                    case SocketAddressFamily.Sna:
                        break;
                    case SocketAddressFamily.Ccitt:
                        break;
                    case SocketAddressFamily.Datakit:
                        break;
                    case SocketAddressFamily.EuropeanComputerManufactures:
                        break;
                    case SocketAddressFamily.Osi:
                    //case SocketAddressFamily.Iso:
                        break;
                    case SocketAddressFamily.Ipx:
                    //case SocketAddressFamily.NS:
                        break;
                    case SocketAddressFamily.Chaos:
                        break;
                    case SocketAddressFamily.Pup:
                        break;
                    case SocketAddressFamily.ImpLink:
                        break;
                    case SocketAddressFamily.Internet:
                        Console.WriteLine($"IPV4 Address: {((IpV4SocketAddress)address.Address).Address}");
                        break;
                    case SocketAddressFamily.Unix:
                        break;
                    case SocketAddressFamily.Unspecified:
                        break;
                    default:
                        break;
                }

                if (address.Netmask != null)
                    Console.WriteLine(("\tNetmask: " + address.Netmask));
                if (address.Broadcast != null)
                    Console.WriteLine(("\tBroadcast Address: " + address.Broadcast));
                if (address.Destination != null)
                    Console.WriteLine(("\tDestination Address: " + address.Destination));
            }
            Console.WriteLine();
        }
        #endregion
    }
}
